<?php
/*
	收入明细
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$params['uniacid']=$_SESSION['uniacid'];
	if($_RQ['storeid']){
		$params['storeid']=$_RQ['storeid'];
		$params2['storeid']=$_RQ['storeid'];
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['title']){
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['cardno']){
		$params2['cardno like']='%'.trim($_RQ['cardno']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['cardno']=$_RQ['cardno'];
	}
	if($_RQ['type']){
		$params['type']=$_RQ['type'];
		$return['params']['type']=$_RQ['type'];
	}
	if($_RQ['jiao_day']){
		$params['jiao_day']=$_RQ['jiao_day'];
		$return['params']['jiao_day']=$_RQ['jiao_day'];
	}
	if($_RQ['zhanghu']){
		$params['zhanghu']=$_RQ['zhanghu'];
		$return['params']['zhanghu']=$_RQ['zhanghu'];
	}
	//创建时间
	if($_RQ['jiao_time']){
		$time_range=cfc('tools')->base64_decode($_RQ['jiao_time'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['jiao_time']=$time_range;
		$params['jiao_time between']=array($time_range['tstart'],$time_range['tend']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:50;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$total='';
	$list=pdo_getslice('jy_yxw_feelog',$params,array($pindex,$psize),$total,$fields,'','jiao_time desc,id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('member')->member_show($item['memberid']);
			if(!$item['shoustoreid'] && $item['status']==1 && $item['type']==1){
				$item['shoustoreid']=pdo_getcolumn('jy_yxw_yonghu',array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$item['memberid']),'storeid');
				pdo_update('jy_yxw_infee_log',array('shoustoreid'=>$item['shoustoreid']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
			}
			$member=pdo_get('jy_yxw_member',array('id'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']),array('title','cardno','worker5id','worker6id','workerheid'));
			$item['worker6title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker6id']),'title');
			$item['worker6title']=$item['worker6title']?:'无';
			$item['worker5title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker5id']),'title');
			$item['worker5title']=$item['worker5title']?:'无';
			$item['createtime']=date('Y-m-d',$item['createtime']);
			$item['jiao_day']=date('Y-m-d',$item['jiao_time']);
			if(!$item['status'] && $item['tofee']>0){
				$item['fee']=$item['tofee'];
			}
			if(!$item['worker6id'] && $member['worker6id']){
				$this->update('infee_log',array('worker6id'=>$member['worker6id']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
			}
			if($member['workerheid']){
				$workerhe=pdo_get('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['workerheid']),array('juese','title'));
				$item['workerhetitle']=$this->user_juese[$workerhe['juese']].':'.$workerhe['title'];
				$item['ishefee']=1;
				if(!$item['workerheid']){
					$this->update('infee_log',array('workerheid'=>$member['workerheid']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
				}
			}
			if(!$item['storeid']){
				$update=array(
					'storeid'=>$member['storeid'],
					'shoustoreid'=>$member['shoustoreid'],
					'koubei_storeid'=>$member['koubei_storeid'],
					'workerid'=>$member['workerid'],
					'worker5id'=>$member['worker5id'],
					'worker6id'=>$member['worker6id'],
					'workerheid'=>$member['workerheid'],
					'up_workerid'=>$member['up_workerid'],
					'from1_type'=>$member['from1_type'],
					'from2_type'=>$member['from2_type'],
				);
				$this->update('feelog',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[<red>温馨提示</red>]：这里只显示待处理的收款，已处理的不在这里显示；','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('name'=>'storeid','title'=>'所属门店','type'=>'select2','options'=>'stores'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'shouhoufee','title'=>'售后成本','type'=>'string'),
			array('name'=>'zufee','title'=>'总部费','type'=>'string'),
			array('name'=>'bufee','title'=>'补贴费','type'=>'string'),
			array('name'=>'peifee','title'=>'售后费','type'=>'string'),
			array('name'=>'zhaofee','title'=>'销售费','type'=>'string'),
			array('name'=>'type','title'=>'费用类型','type'=>'radio2','options'=>'feelog_type'),
			array('name'=>'jiao_day','title'=>'交费日期','type'=>'string'),
			array('name'=>'zhanghu','title'=>'到账账户','type'=>'string'),
			array('type'=>'img_string','title'=>'合作成交',
            'data'=>array(
                array('title'=>'销售员:','name'=>'worker6title'),
                array('title'=>'','name'=>'workerhetitle'),
                )
            ),
			array('name'=>'worker5title','title'=>'电客','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'storeid','width'=>10,'title'=>'所属门店','type'=>'select','options'=>'stores'),
			array('name'=>'title','width'=>10,'title'=>'姓名','type'=>'string'),
			array('name'=>'cardno','width'=>10,'title'=>'身份证号','type'=>'string'),
			array('name'=>'type','width'=>10,'title'=>'费用类型','type'=>'radio','options'=>'feelog_type'),
			array('name'=>'jiao_time','width'=>10,'title'=>'交费日期','type'=>'time_range'),
			array('name'=>'zhanghu','width'=>10,'title'=>'到账账户','type'=>'string'),
		)
	);
	$return['status']=array('待审批','审批通过','审批不通过');
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_SESSION['storeids']){
		$params['id']=$_SESSION['storeids'];
	}
	$return['stores']=$this->getall('store',$params,array('id','title'),'id');
	$return['htmls']=$htmls;
	$return['mstatus']=$this->member_status;
	$return['feelog_type']=$this->feelog_type;
	$return['daipay_types']=$this->daipay_types;
	exi($return);
}
